import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../provider/userprovider.dart';

class LoginScreen extends StatefulWidget {
  const LoginScreen({Key? key}) : super(key: key);

  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  TextEditingController emailController = TextEditingController();
  TextEditingController passwordController = TextEditingController();

  void login(String email, password) async {}

  @override
  Widget build(BuildContext context) {
    emailController.text = "daijinming";
    passwordController.text = "123456";

    return Scaffold(
      appBar: AppBar(
        title: const Text('用户登录'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextFormField(
              controller: emailController,
              decoration: InputDecoration(hintText: '帐号'),
            ),
            SizedBox(
              height: 20,
            ),
            TextFormField(
              controller: passwordController,
              decoration: InputDecoration(hintText: '密码'),
            ),
            SizedBox(
              height: 40,
            ),
            GestureDetector(
              onTap: () {
                final postMdl =
                    Provider.of<UserProvider>(context, listen: false);
                postMdl.Login(context, emailController.text.toString(),
                    passwordController.text.toString());
              },
              child: Container(
                height: 50,
                decoration: BoxDecoration(
                    color: Colors.green,
                    borderRadius: BorderRadius.circular(10)),
                child: Center(
                  child: Text('登录'),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
